from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from time import sleep


import sys

sys.path.append(r'..')
from web_base.base_page import BasePage

class LoginPage(BasePage):
    url=r'/bsams/front/asset/asset_list.do'

    #登录定位
    taskid_loc=(By.ID,'taskId')
    username_loc=(By.ID,'loginName')
    password_loc=(By.ID,'password')
    vericode_loc=(By.ID,'vericode')
    login_btn_loc=(By.XPATH,'//*[@id="fmedit"]/div[2]/div[6]/input')
    #退出定位
    logout_bth_loc=(By.CLASS_NAME,'exit.right')
    def login(self,taskid=1,username='wangjiacheng01',password='123456',vericode='shtd'):
        self.open()
        self.input_ele(self.taskid_loc,taskid)
        self.input_ele(self.username_loc,username)
        self.input_ele(self.password_loc,password)
        self.input_ele(self.vericode_loc,vericode)
        self.ele_click(self.login_btn_loc)
        sleep(3)

    def logout(self):
        self.ele_click(self.logout_bth_loc)

if __name__ == '__main__':
    taskid = 1
    username = 'wangjiacheng01'
    password = '123456'
    vericode = 'shtd'

    chrome_location = r'D:\测试工具\Win_x64_1135105_chrome-win\chrome-win\chrome.exe'
    options = webdriver.ChromeOptions()
    options.binary_location = chrome_location
    driver_location = r'D:\测试工具\pythan\chromedriver.exe'
    service = Service(driver_location)

    driver=webdriver.Chrome(options=options,service=service)

    login_page=LoginPage(driver)
    login_page.login(taskid,username,password,vericode)
    login_page.logout()
    driver.quit()

